#include "slideshowdialog.h"
#include "ui_slideshowdialog.h"
#include"prelistwid.h"
#include"protreewidget.h"

SlideShowDialog::SlideShowDialog(QWidget *parent, QTreeWidgetItem *first_item, QTreeWidgetItem *last_item):
    QDialog(parent),
    ui(new Ui::SlideShowDialog),
    _first_item(first_item),
    _last_item(last_item)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::Dialog|Qt::FramelessWindowHint);
    ui->slidePreBtn->setIcons(":/icon/previous.png",
                              ":/icon/previous_hover.png",
                              ":/icon/previous_press.png");

    ui->slideNextBtn->setIcons(":/icon/next.png",
                              ":/icon/next_hover.png",
                              ":/icon/next_press.png");

    ui->closeBtn->setIcons(":/icon/closeshow.png",
                              ":/icon/closeshow_hover.png",
                              ":/icon/closeshow_press.png");

    ui->playBtn->setIcons(":/icon/play.png",
                          ":/icon/play_hover.png",
                          ":/icon/play_press.png",
                          ":/icon/pause.png",
                          ":/icon/pause_press.png",
                          ":/icon/pause_press.png");
    connect(ui->closeBtn, &QPushButton::clicked, this, &SlideShowDialog::close);
    connect(ui->slideNextBtn, &QPushButton::clicked, ui->picAnimation, &PicAnimationWid::SlideNext);
    connect(ui->slidePreBtn, &QPushButton::clicked, ui->picAnimation, &PicAnimationWid::SlidePre);

    auto *preListWid = dynamic_cast<PreListWid*>(ui->preListWidget);
    connect(ui->picAnimation, &PicAnimationWid::SigUpPreList, preListWid, &PreListWid::SlotUpPreList);
    connect(ui->picAnimation, &PicAnimationWid::SigSelectItem, preListWid, &PreListWid::SlotUpSelect);

    connect(preListWid, &PreListWid::SigUpSelectShow, ui->picAnimation, &PicAnimationWid::SlotUpSelectShow);

    connect(ui->playBtn, &PicStateBtn::clicked, ui->picAnimation, &PicAnimationWid::SlotStartOrStop);
    connect(ui->picAnimation, &PicAnimationWid::SigStart, ui->playBtn, &PicStateBtn::SlotStart);
    connect(ui->picAnimation, &PicAnimationWid::SigStop, ui->playBtn, &PicStateBtn::SlotStop);
    auto* pro_tree_widget = dynamic_cast<ProTreeWidget*>(this->parent());
    connect(ui->picAnimation, &PicAnimationWid::SigStartMusic, pro_tree_widget, &ProTreeWidget::SlotStartMusic);
    connect(ui->picAnimation, &PicAnimationWid::SigStopMusic, pro_tree_widget, &ProTreeWidget::SlotStopMusic);
    connect(ui->closeBtn, &QPushButton::clicked, pro_tree_widget, &ProTreeWidget::SlotStopMusic);

    ui->picAnimation->SetPixmap(first_item);
    ui->picAnimation->Start();
}

SlideShowDialog::~SlideShowDialog()
{
    delete ui;
}
